package com.polaris.live.adapter.party

import android.view.View
import com.blankj.utilcode.util.StringUtils
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.databinding.AdapterPartyCoverTypeBinding
import com.polaris.live.resp.back_resp.PartyGameResp
import com.polaris.live.translation.R.string

/**
 * PartyCoverTypeAdapter
 *
 * @author Created by 半仙 on 2024/3/14/014 22:00
 */
class PartyCoverTypeAdapter : BaseBindingAdapter<AdapterPartyCoverTypeBinding, Any>() {
    private var selectPosition = 0
    override fun convert(holder: VBViewHolder<AdapterPartyCoverTypeBinding>, item: Any) {
        holder.vb.apply {
            if (item is PartyGameResp) {
                partyTypeItemTv.text = item.name
            } else {
                when (item) {
                    PARTY -> {
                        partyTypeItemTv.text = StringUtils.getString(string.party)
                    }

                    VIDEOPARTY -> {
                        partyTypeItemTv.text = StringUtils.getString(string.video_party)
                    }
                }

            }
            if (selectPosition == holder.absoluteAdapterPosition) {
                partyTypeSelectBack.visibility = View.VISIBLE
            } else {
                partyTypeSelectBack.visibility = View.GONE
            }
        }
    }

    fun setSelect(position: Int) {
        selectPosition = position
        notifyDataSetChanged()
    }

    fun getSelectItem() = data.getOrNull(selectPosition)

    companion object {
        const val PARTY = 1
        const val VIDEOPARTY = 2
    }
}